package com.msb.dongbao.portal.web.controller;

import com.msb.dongbao.common.base.annotations.TokenCheck;
import com.msb.dongbao.common.base.result.ResultWrapper;
import com.msb.dongbao.entity.UmsMember;
import com.msb.dongbao.entity.dto.UmsMemberLoginParamDTO;
import com.msb.dongbao.entity.dto.UmsMemberRegisterParamDTO;
import com.msb.dongbao.service.UmsMemberService;
import com.msb.msbdongbaocommonutil.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/ums-member")
public class UserMemberController {

    @Autowired
    UmsMemberService umsMemberService;

    /**
     * 获取验证码
     * @return
     */
    @GetMapping("/get-captcha")
    public String getCaptcha(){

        return "获取验证码";
    }

    /**
     * 注册
     * @param umsMemberRegisterParamDTO
     * @return
     */
    @PostMapping("/register")
    public ResultWrapper register(@RequestBody  @Valid UmsMemberRegisterParamDTO umsMemberRegisterParamDTO) {
       return umsMemberService.register(umsMemberRegisterParamDTO);

    }

    /**
     * 登录
     * @param umsMemberLoginParamDTO
     * @return
     */
    @PostMapping("/login")
    public ResultWrapper login(@RequestBody UmsMemberLoginParamDTO umsMemberLoginParamDTO) {
        return umsMemberService.login(umsMemberLoginParamDTO);
    }

    @PostMapping("/edit")
    @TokenCheck
    public ResultWrapper edit(@RequestBody UmsMember umsMember){
        return umsMemberService.edit(umsMember);
    }


    @GetMapping("/test-verify")
    public String verify(String token){
        String s = JwtUtil.parseToken(token);
        return s;
    }

}
